//
//  LSDataBankVController.m
//  LookScore
//
//  Created by wr on 2018/1/27.
//  Copyright © 2018年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSDataBankVController.h"
#import "LSIntercontinentalMatchVController.h"
#import "ZJScrollPageView.h"

@interface LSDataBankVController ()<ZJScrollPageViewDelegate>

@property(strong, nonatomic)NSArray<NSString *> *titles;

@property(strong, nonatomic)NSArray<UIViewController *> *childVcs;

@property (nonatomic, strong) ZJScrollPageView *scrollPageView;

@property(strong,nonatomic)NSArray *allLeagueListArr;

@end

@implementation LSDataBankVController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBar.translucent = NO;
//    self.navigationController.navigationBar.h
    self.navigationController.navigationBar.alpha = 1 ;
}

-(NSArray *)allLeagueListArr{
    if (!_allLeagueListArr) {
        _allLeagueListArr = [NSArray array];
    }
    return _allLeagueListArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    if ([CommonClass isBlankString:self.titleString]) {
//        self.title=@"资料库";
//    }else{
//        self.title=self.titleString;
//    }
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self loadAllLeagueList];
}
- (void)initUI{
    
    
    ZJSegmentStyle *style = [[ZJSegmentStyle alloc] init];
    //显示滚动条
    style.showLine = YES;
    // 颜色渐变
    style.gradualChangeTitleColor = YES;
    
    style.scrollLineColor=LSNavMainColor;
    
    style.segmentHeight=35;
    
    style.autoAdjustTitlesWidth=YES;
    
    style.normalTitleColor=[UIColor colorWithRed:255.f/255.f green:255.f/255.f blue:255.f/255.f alpha:1];
    
    style.selectedTitleColor=LSNavTitlenColor;
    
    style.scrollLineColor=LSNavTitlenColor;
    
    self.titles = @[@"热门", @"欧洲",@"亚洲", @"美洲",@"非洲",@"大洋洲",@"国际"];
    // 初始化
    _scrollPageView = [[ZJScrollPageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,self.view.bounds.size.height) segmentStyle:style titles:self.titles parentViewController:self delegate:self];
    _scrollPageView.segmentView.backgroundColor=LSNavMainColor;
    [self.view addSubview:_scrollPageView];
}
-(void)loadAllLeagueList{
    MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    //    hud.label.text=@"正在请求中...";
    hud.mode=MBProgressHUDModeIndeterminate;
    [LSHttpEnclosureTool GET:LSAllLeagueList parameters:nil resBlock:^(id responseObject) {
        if (responseObject) {
            self.allLeagueListArr = responseObject;
            [hud hideAnimated:YES];
            [self initUI];
        }
    }];
}

- (NSInteger)numberOfChildViewControllers {
    return self.titles.count;
}

- (UIViewController<ZJScrollPageViewChildVcDelegate> *)childViewController:(UIViewController<ZJScrollPageViewChildVcDelegate> *)reuseViewController forIndex:(NSInteger)index {
    NSArray *leagueListArr = [self dataClassification:index].copy;
    UIViewController<ZJScrollPageViewChildVcDelegate> *childVc = reuseViewController;
    
    if (!childVc) {
        LSIntercontinentalMatchVController *IMVC = [[LSIntercontinentalMatchVController alloc] init];
        IMVC.leagueListArr = leagueListArr;
        childVc = IMVC;
    }
    
    return childVc;
}

- (NSMutableArray *)dataClassification:(NSInteger)index{
    NSMutableArray *leagueListArr = [NSMutableArray array];
    [leagueListArr removeAllObjects];
    NSArray *classesArr = @[@"",@"欧洲赛事",@"亚洲赛事",@"美洲赛事",@"非洲赛事",@"大洋洲赛事",@"国际赛事"];
    if ([self.titles[index] isEqualToString:@"热门"]) {
        for (NSDictionary *dic in self.allLeagueListArr) {
            if ([dic[@"LeagueName"] isEqualToString:@"英超"] || [dic[@"LeagueName"] isEqualToString:@"西甲"] || [dic[@"LeagueName"] isEqualToString:@"德甲"] || [dic[@"LeagueName"] isEqualToString:@"意甲"] || [dic[@"LeagueName"] isEqualToString:@"法甲"] || [dic[@"LeagueName"] isEqualToString:@"中超"] || [dic[@"LeagueName"] isEqualToString:@"日职联"] || [dic[@"LeagueName"] isEqualToString:@"亚冠杯"] || [dic[@"LeagueName"] isEqualToString:@"欧冠杯"]) {
                [leagueListArr addObject:dic];
            }
        }
    }else{
        for (NSDictionary *dic in self.allLeagueListArr) {
            if ([dic[@"FirstLeagueBelongsName"] isEqualToString:classesArr[index]]) {
                [leagueListArr addObject:dic];
            }
        }
    }
    MyLog(@"leagueListArr --- %@",leagueListArr);
    return leagueListArr;
}

- (BOOL)shouldAutomaticallyForwardAppearanceMethods {
    return NO;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

